package sk.naive.talker.command;

import sk.naive.talker.util.Utils;
import sk.naive.talker.persistence.PersistenceException;
import sk.naive.talker.props.PropertyStoreException;

import java.rmi.RemoteException;
import java.util.Set;
import java.util.logging.Level;

/**
 *
 * @author <a href="mailto:virgo@naive.deepblue.sk">Richard "Virgo" Richter</a>
 * @version $Revision: 1.8 $ $Date: 2005/01/11 22:19:13 $
 */
public class TalkerSet extends AbstractSetCommand {
	public static final String PERM_TALKER_SET = "talkerSet";

	protected void permissionCheck() throws PermissionException, RemoteException {
		Utils.checkPermission(user, PERM_TALKER_SET);
	}

	protected String setValue(String key, String value)
		throws RemoteException,
		PropertyStoreException,
		PersistenceException
	{
		getTalker().set(key, getTalker().getProperty(key).toObject(value));
		logger().log(Level.INFO, "User {0} set talker property ''{1}'' to ''{2}''.", new Object[] {user.getLogin(), key, value});
		return value;
	}

	protected Set<String> getValidValues(String key) throws RemoteException {
		return getTalker().getProperty(key).validValues();
	}

	protected String getValue(String key) throws RemoteException, PropertyStoreException {
		return getTalker().getProperty(key).toString(getTalker().get(key));
	}

	protected Set<String> settable() {
		return getTalker().getSettable();
	}
}